package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.DistributorAccountEnum;
import com.xbongbong.saas.enums.dictionary.DistributorRoleEnum;
import com.xbongbong.saas.enums.dictionary.DistributorAccountStatusEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 经销商账号
 * @author xinpeng.jiang
 * @date 2020/12/21 16:23
 * @version 1.0
 * @since V1.0
 */
@Getter
public enum TempAccountDistributorEnum {
    //经销商账号
    BASE_INFO(DistributorAccountEnum.BASE_INFO),
    NAME(DistributorAccountEnum.NAME),
    PHONE(DistributorAccountEnum.PHONE),
    AUTHORITY(DistributorAccountEnum.AUTHORITY),
    DISTRIBUTOR_NAME(DistributorAccountEnum.DISTRIBUTOR_NAME),
    ACCOUNT_STATUS(DistributorAccountEnum.ACCOUNT_STATUS),

    SYSTEM_INFO(DistributorAccountEnum.SYSTEM_INFO),
    CREATOR_ID(DistributorAccountEnum.CREATOR_ID),
    ADD_TIME(DistributorAccountEnum.ADD_TIME),
    UPDATE_TIME(DistributorAccountEnum.UPDATE_TIME),
    DISTRIBUTOR_NAME_LINK_TEXT(DistributorAccountEnum.DISTRIBUTOR_NAME_LINK_TEXT),
    ;
    /**
     * 经销商账号枚举
     */
    private DistributorAccountEnum anEnum;

    TempAccountDistributorEnum(DistributorAccountEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempAccountDistributorEnum> getAllEnum() {
        List<TempAccountDistributorEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initName(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(NAME.getAnEnum().getAttr());
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initAuthority(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(DistributorRoleEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    public static void initAccountStatus(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(DistributorAccountStatusEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    /**
     * 初始化关联经销商
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initDistributorName(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(DISTRIBUTOR_NAME_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(DISTRIBUTOR_NAME.getAnEnum().getAttr());
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

}
